package com.bba.manager.user.controller;

import com.bba.manager.common.model.user.Customer;
import com.bba.manager.common.model.user.VO.customerPageVO;
import com.bba.manager.common.model.user.VO.query;
import com.bba.manager.common.util.ResponseVO;
import com.bba.manager.user.service.ICustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author SYANDZZY
 * @since 2025-08-11
 */
@RestController
@RequestMapping("/customer")
public class CustomerController {
    @Autowired
    private ICustomerService customerService;
    //添加客户信息
    @GetMapping("/addCustomer")
    public ResponseVO addCustomer( Customer customer){
        customerService.saveCustomer(customer);
        return ResponseVO.success(customer);
    }
    //根据客户身份证删除客户信息
    @PostMapping("/deleteCustomer")
    public ResponseVO deleteCustomer(@RequestBody Customer customer){
        customerService.removeById(customer.getId());
        return ResponseVO.success(customer);
    }
    //分页查询客户
    @GetMapping("/getList")
    public ResponseVO listCustomer( query query){
        customerPageVO customerPageVO = new customerPageVO();
        customerPageVO.setPage(query.getPage());
        customerPageVO.setLimit(query.getLimit());
        return ResponseVO.success(customerService.listCustomer(customerPageVO));
    }
    //根据姓名查询客户
    @GetMapping("/listCustomerByName")
    public ResponseVO listCustomerByName(@RequestParam String name){
        return ResponseVO.success(customerService.listCustomerByName(name));
        }

    //修改客户信息
    @PostMapping("/update")
    public ResponseVO updateCustomer( Customer customer){
        customerService.updateById(customer);
        return ResponseVO.success(customer);
    }
    //获取所有用户信息
    @GetMapping("/list")
    public ResponseVO list(){
        return ResponseVO.success(customerService.list());
    }

}
